package account

import (
	"context"

	"core/contract/db"
	coreIError "core/contract/error"
	"core/enum/response"
	model "core/model/mysql"
	errorSvc "core/service/error"
)

type EditApi struct {
	DbFactory db.IDbFactory `inject:""`
}

func (e EditApi) Call(ctx context.Context) (interface{}, coreIError.IError) {
	var account model.Account
	err := e.DbFactory.Build(ctx).Where("id = ?", 15).Take(&account)
	if err != nil {
		return nil, errorSvc.NewError(response.Fail, err)
	}

	account.AccountName = "hcc6666"
	err = e.DbFactory.Build(ctx).Save(&account)
	if err != nil {
		return nil, errorSvc.NewError(response.Fail, err)
	}

	return account, nil
}
